package com.lwt.db137.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lwt.db137.bean.Menu;
import com.lwt.db137.bean.Role;
import com.lwt.db137.bean.RoleMenu;
import com.lwt.db137.commen.R;
import com.lwt.db137.service.RolemenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author lwt
 * @version 1.0
 * @Description
 * @date 2024/12/24 11:43
 */
@RestController
@CrossOrigin(origins = "*")
public class RoleMenuController {
    @Autowired
    private RolemenuService  rolemenuService;
    @GetMapping("/roleMenu/{roleid}")
    public R getRoleMenu(@PathVariable("roleid") int roleid){
        QueryWrapper<RoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("roleid",roleid);
        return new R().addData("roleMenu",rolemenuService.list(queryWrapper));

    }
    @PostMapping("updateRoleMenu")
    public R updateRoleMenu(@RequestBody Map<String,Object> map){
        System.out.println("menuids = " + map);
        int roleid = Integer.parseInt(map.get("roleId")+""); //获取角色id
        List<Integer> menuids = (List<Integer>) map.get("menuIds"); //获取菜单id列表
        return new R().addData("updateRoleMenu",rolemenuService.updateRoleMenu(roleid,menuids));
    }

}
